package com.kabuda.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * @author kabuda
 * @create 2023-10-15 12:03
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class R {
    private boolean state;
    private int code;
    private String msg;
    private Map<String,Object> data;

    public static R success(){
        R r = new R();
        r.setState(true);
        r.setCode(200);
        r.setMsg("SUCCESS");
        return r;
    }
    public static R success(Map<String,Object> data){
        R r = new R();
        r.setState(true);
        r.setCode(200);
        r.setMsg("SUCCESS");
        r.setData(data);
        return r;
    }

    public static R success(String key,Object value){
        R r = new R();
        r.setState(true);
        r.setCode(200);
        r.setMsg("SUCCESS");
        HashMap<String, Object> map = new HashMap<>();
        map.put(key,value);
        r.setData(map);
        return r;
    }
    public static R success(Object value){
        R r = new R();
        r.setState(true);
        r.setCode(200);
        r.setMsg("SUCCESS");
        HashMap<String, Object> map = new HashMap<>();
        map.put("data",value);
        r.setData(map);
        return r;
    }

    public static R success(String msg,Map<String,Object> data){
        R r = new R();
        r.setState(true);
        r.setCode(200);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }


    public static R fail(){
        R r = new R();
        r.setState(false);
        r.setCode(100);
        r.setMsg("Fail");
        return r;
    }
    public static R fail(int code){
        R r = new R();
        r.setState(false);
        r.setCode(code);
        r.setMsg("Fail");
        return r;
    }
    public static R fail(int code,String msg){
        R r = new R();
        r.setState(false);
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }
}
